package edu.drexel.jrexel2d.networking.socket;

import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class ServerMasterSocket extends GameSocket {
	private int acceptedConnections;

	public ServerMasterSocket(int port) {
		acceptedConnections = 0;
		this.port = port;

	}

	public void initialize() throws SocketException {
		socket = new DatagramSocket(port);
		socket.setSoTimeout(1);

	}

	public GameServerSocket acceptConnection(InetAddress clientIp,
			int clientPort) {
		GameServerSocket serverSocket = new GameServerSocket(port
				+ (acceptedConnections + 1));
		acceptedConnections++;
		try {
			serverSocket.getSocket().setSoTimeout(1);
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return serverSocket;

	}
}
